1
|
|
package net.sf.flock.hibernate;
|
2
|
|
|
3
|
|
import java.net.MalformedURLException;
|
4
|
|
import java.net.URL;
|
5
|
|
import java.sql.PreparedStatement;
|
6
|
|
import java.sql.ResultSet;
|
7
|
|
import java.sql.SQLException;
|
8
|
|
|
9
|
|
import cirrus.hibernate.Hibernate;
|
10
|
|
import cirrus.hibernate.HibernateException;
|
11
|
|
import cirrus.hibernate.UserType;
|
12
|
|
|
13
|
|
public class URLType implements UserType {
|
14
|
|
|
15
|
|
private final static int[] TYPES = new int[] { java.sql.Types.VARCHAR };
|
16
|
|
|
17
|
|
/**
|
18
|
|
* @see cirrus.hibernate.UserType#sqlTypes()
|
19
|
|
*/
|
20
|
4
|
public int[] sqlTypes() {
|
21
|
4
|
return TYPES;
|
22
|
|
}
|
23
|
|
|
24
|
|
/**
|
25
|
|
* @see cirrus.hibernate.UserType#returnedClass()
|
26
|
|
*/
|
27
|
0
|
public Class returnedClass() {
|
28
|
0
|
return java.net.URL.class;
|
29
|
|
}
|
30
|
|
|
31
|
|
/**
|
32
|
|
* @see cirrus.hibernate.UserType#equals(java.lang.Object, java.lang.Object)
|
33
|
|
*/
|
34
|
6
|
public boolean equals(Object x, Object y) {
|
35
|
6
|
if (x==y) return true;
|
36
|
0
|
if (x==null || y==null) return false;
|
37
|
0
|
return x.equals(y);
|
38
|
|
}
|
39
|
|
|
40
|
|
/**
|
41
|
|
* @see cirrus.hibernate.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String, java.lang.Object)
|
42
|
|
*/
|
43
|
4
|
public Object nullSafeGet(ResultSet rs, String[] names, Object o) throws HibernateException, SQLException {
|
44
|
4
|
String url = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
|
45
|
4
|
if (url==null) {
|
46
|
0
|
return null;
|
47
|
|
}
|
48
|
4
|
try {
|
49
|
4
|
return new URL(url);
|
50
|
|
} catch (MalformedURLException e) {
|
51
|
0
|
throw new HibernateException(e);
|
52
|
|
}
|
53
|
|
}
|
54
|
|
|
55
|
|
/**
|
56
|
|
* @see cirrus.hibernate.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
|
57
|
|
*/
|
58
|
5
|
public void nullSafeSet(PreparedStatement ps, Object value, int index) throws HibernateException, SQLException {
|
59
|
5
|
Hibernate.STRING.nullSafeSet(ps, value==null ? null : ((URL)value).toExternalForm(), index);
|
60
|
|
}
|
61
|
|
|
62
|
|
/**
|
63
|
|
* @see cirrus.hibernate.UserType#deepCopy(java.lang.Object)
|
64
|
|
*/
|
65
|
8
|
public Object deepCopy(Object x) {
|
66
|
8
|
return x;
|
67
|
|
}
|
68
|
|
|
69
|
|
/**
|
70
|
|
* @see cirrus.hibernate.UserType#isMutable()
|
71
|
|
*/
|
72
|
0
|
public boolean isMutable() {
|
73
|
0
|
return false;
|
74
|
|
}
|
75
|
|
|
76
|
|
}
|